package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.dto.CreateOrderRespDto;
import io.renren.modules.app.req.CreateOrderReq;
import io.renren.modules.app.vo.CreateOrderPayVO;
import io.renren.modules.app.vo.CreateOrderVO;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.app.entity.OrderEntity;
import io.renren.modules.app.service.OrderService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



/**
 * 订单表
 *
 * @author MR.XU
 * @email 260139486@qq.com
 * @date 2021-01-19 10:04:49
 */
@RestController
@RequestMapping("api/order")
@Api(value = "订单表", tags = "APP订单控制器")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * @description: 用户下单
     * @auther: create by Administrator - MR.XU email:260139486@qq.com
     * @date 2021-01-19 10:04:49
     * @param
     * @return
     */
    @PostMapping("/createOrder")
    @Login
    @ApiOperation("用户下单")
    public R createOrder(@RequestBody CreateOrderReq createOrderReq){
        log.info("==============[订单]   用户创建订单,参数:{}",createOrderReq.toString());
        CreateOrderVO resp = orderService.createOrder(createOrderReq);
        return R.ok().put("data",resp);
    }
    /**
     * @description: 继续支付
     * @auther: create by Administrator - MR.XU email:260139486@qq.com
     * @date 2021-01-19 10:04:49
     * @param
     * @return
     */
    @ApiOperation(value = "继续支付", response = CreateOrderRespDto.class)
    @GetMapping("/orderPay/{orderCode}")
    @Login
    public R orderPay(@PathVariable("orderCode") String orderCode) {
        CreateOrderPayVO createOrderPayVO =  orderService.continuePay(orderCode);
        return R.ok().put("data",createOrderPayVO);
    }
    /**
     * @description: 余额支付
     * @auther: create by Administrator - MR.XU email:260139486@qq.com
     * @date 2021-01-19 10:04:49
     * @param
     * @return
     */
    @ApiOperation(value = "余额支付", response = CreateOrderRespDto.class)
    @GetMapping("/orderBalancePay/{orderCode}")
    @Login
    public R orderBalancePay(@PathVariable("orderCode") String orderCode) {
        orderService.orderBalancePay(orderCode);
        return R.ok();
    }
    /**
     * @description: 用户取消订单
     * @auther: create by Administrator - MR.XU email:260139486@qq.com
     * @date 2021-01-19 10:04:49
     * @param
     * @return
     */
    @GetMapping("/cancelOrder")
    @Login
    @ApiOperation("用户取消订单")
    public R userCancelOrder(String orderId){
        log.info("========================[订单] 用户取消订单,参数:{}",orderId);
        orderService.cancelOrder(orderId);
        return R.ok();
    }
}
